#include <iostream>

using namespace std;

//菱形继承
//两个派生类继承同一个基类,又有某个类同时继承了两个派生类,这种继承被称为菱形继承,或者钻石继承
//利用虚继承 解决菱形继承的问题
//Animal称为虚基类
//动物
class Animal {
public:
    int age;
};

//继承前加virtual关键字后，变为虚继承
//此时公共的父类Animal称为虚基类
//羊
class Sheep : virtual public Animal {

};

//骆驼
class Camel : virtual public Animal {

};

//羊驼
class Alpaca : public Sheep, public Camel {

};

void test1() {
    Alpaca alpaca;
    alpaca.Sheep::age = 18;
    alpaca.Camel::age = 28;
    //当菱形继承时，两个父类拥有相同的数据，需要加以作用域区分
    cout << "Sheep:age=" << alpaca.Sheep::age << endl;
    cout << "Camel:age=" << alpaca.Camel::age << endl;
    cout << "Alpaca:ahe=" << alpaca.age << endl;
}

int main() {
    test1();
    return 0;
}